import { IndicatorSystemDetailItem } from "@/api";
import {
  approvalResultOptions,
  // approvalStatusMap,
  // IndicatorStatusEnum,
  // indicatorStatusMap,
  projectPrototypeForm,
} from "@/utils";
import { cloneDeep } from "lodash-es";
const scoreColumn = {
  title: "得分",
  dataIndex: "score",
  width: 50,
  resizable: true,
  ellipsis: true,
  customRender: (params: any) => {
    const { text } = params;
    return (
      <span>
        <span class="table-cell-indent"></span>
        {text || "-"}
      </span>
    );
  },
};
const weightsColumn = {
  title: "相对权重",
  dataIndex: "weights",
  width: 50,
  resizable: true,
  ellipsis: true,
  customRender: (params: any) => {
    const { text } = params;
    return (
      <span>
        <span class="table-cell-indent"></span>
        {![undefined, "", null].includes(text) ? text + "%" : "-"}
      </span>
    );
  },
};
const basicFormConfig: FormItem[] = [
  {
    type: "input",
    label: "项目名称",
    key: "projectName",
    props: {
      placeholder: "用于项目名称的标记",
    },
  },
  {
    type: "editor",
    label: "项目介绍",
    key: "projectDesc",
    props: {
      editorConfig: { placeholder: "请输入项目内容介绍" },
      toolbarConfig: {},
    },
  },
  ...projectPrototypeForm,
  {
    type: "range-picker",
    label: "项目持续时间",
    key: "rangeDates",
    props: {
      placeholder: ["预计开始日期", "预计结束日期"],
    },
  },
  {
    type: "input",
    label: "建筑面积",
    key: "constructArea",
    props: {
      placeholder: "请填写项目面积",
      suffix: "平方米",
    },
  },
  {
    type: "input",
    label: "产权归属",
    key: "propertyOwnership",
  },
  {
    type: "input",
    label: "产权方代表",
    key: "propertyOwner",
    props: {
      placeholder: "产权方主要联系人",
    },
  },
  {
    type: "input",
    label: "产权方邮箱",
    key: "propertyOwnerEmail",
  },
  {
    type: "input",
    label: "产权方联系方式",
    key: "propertyOwnerContact",
  },
  {
    type: "input",
    label: "产权方类型",
    key: "propertyOwnerType",
  },
  {
    type: "input",
    label: "产权方所在地区",
    key: "propertyOwnerLocation",
  },
];
const projectFormConfig: FormItem[] = [
  {
    type: "input",
    label: "国家/地区",
    key: "country",
  },
  {
    type: "input",
    label: "省市州",
    key: "province",
  },
  {
    type: "input",
    label: "市/县/区",
    key: "city",
  },
  {
    type: "input",
    label: "街道",
    key: "street",
  },
  {
    type: "input",
    label: "地址",
    key: "location",
  },
  {
    type: "input",
    label: "邮政编码",
    key: "postalCode",
  },
  {
    type: "input",
    label: "地理位置-经度",
    key: "longitude",
    required: false,
  },
  {
    type: "input",
    label: "地理位置-纬度",
    key: "latitude",
    required: false,
  },
];
export const basicInfoForm = basicFormConfig.concat(
  [
    {
      type: "divider",
      label: "项目地址",
    },
  ],
  projectFormConfig,
  [
    {
      type: "divider",
      label: "",
    },
    {
      key: "fileList",
      type: "upload",
      label: "项目协议",
      props: {
        // templateName: "指导导则模版",
        maxCount: 1,
      },
    },
  ]
);
export const getRadarChartOptions = (
  indicators: IndicatorSystemDetailItem[]
) => ({
  radar: {
    indicator: indicators.map((item) => ({
      name: item.name,
      max: 100, // +item.weights,
    })),
    axisLine: {
      show: true,
      lineStyle: {
        opacity: 0.5,
      },
    },
    splitArea: {
      areaStyle: {
        color: ["transparent", "rgb(220,251,239)"],
      },
    },
  },
  series: [
    {
      name: "radar",
      type: "radar",
      itemStyle: {
        color: "rgb(113,181,2)",
      },
      lineStyle: {
        color: "rgb(113,181,2)",
      },
      data: [
        {
          value: indicators.map((item) => item.score),
          name: "radar",
        },
      ],
    },
  ],
});
export const getPieChartOptions = (indicators: IndicatorSystemDetailItem[]) => {
  const avg = 100 / indicators.length;
  return {
    color: indicators.map(
      (item, index) => `rgba(6,221,141,${Math.round(100 - avg * index) / 100})`
    ),
    series: [
      {
        name: "pie",
        type: "pie",
        radius: ["25%", "45%"],
        avoidLabelOverlap: false,
        label: {
          show: true,
          formatter: "{b}: {c}%",
        },
        data: indicators.map((item) => ({
          name: item.name,
          value: +item.weights,
        })),
      },
    ],
  };
};
export const getApprovalColumns = () =>
  cloneDeep([
    {
      title: "名称",
      dataIndex: "name",
      width: 100,
      resizable: true,
      ellipsis: true,
    },
    {
      title: "指标类型",
      dataIndex: "type",
      // customRender: ({ text }: { text: IndicatorTypeEnum }) =>
      //   indicatorTypeMap[text],
      width: 50,
      resizable: true,
      ellipsis: true,
    },
    weightsColumn,
    scoreColumn,
  ]);
export const getFillColumns = () =>
  cloneDeep([
    {
      title: "名称",
      dataIndex: "name",
      width: 100,
      resizable: true,
      ellipsis: true,
    },
    {
      title: "指标类型",
      dataIndex: "type",
      width: 50,
      resizable: true,
      ellipsis: true,
    },
    {
      title: "状态",
      dataIndex: "statusName",
      width: 50,
      resizable: true,
      ellipsis: true,
    },
    weightsColumn,
    scoreColumn,
    {
      title: "操作",
      dataIndex: "action",
      width: 100,
      resizable: true,
      ellipsis: true,
    },
  ]);
export const getIndicatorColumns = () =>
  cloneDeep([
    {
      title: "名称",
      dataIndex: "name",
      width: 200,
      resizable: true,
      ellipsis: true,
    },
    {
      title: "指标类型",
      dataIndex: "type",
      width: 90,
      resizable: true,
      ellipsis: true,
    },
    {
      title: "分值",
      dataIndex: "",
      width: 60,
      resizable: true,
      ellipsis: true,
      align: "right",
      customRender: () => 100,
    },
    { ...weightsColumn, width: 60, align: "right" },
    {
      title: "权重分值",
      dataIndex: "weights",
      width: 90,
      resizable: true,
      ellipsis: true,
      align: "right",
    },
    {
      title: "是否参与评分",
      dataIndex: "canApproval",
      width: 120,
      resizable: true,
      ellipsis: true,
    },
    // {
    //   title: "操作",
    //   dataIndex: "action",
    //   width: 100,
    // },
  ]);
export const approvalFormConfig: FormItem[] = [
  {
    type: "input-number",
    label: "评分",
    key: "score",
    props: {
      autocomplete: "off",
    },
  },
  {
    type: "select",
    label: "评审结果",
    key: "approvalResult",
    props: {
      options: approvalResultOptions,
    },
  },
  {
    type: "editor",
    label: "专家意见",
    key: "approvalComments",
    props: {
      toolbarConfig: {},
    },
  },
  {
    type: "editor",
    label: "提升策略建议",
    key: "approvalSuggests",
    props: {
      toolbarConfig: {},
    },
  },
];
export const getApprovalIndicatorColumns = () =>
  cloneDeep([
    {
      title: "名称",
      dataIndex: "name",
      width: 100,
      resizable: true,
      ellipsis: true,
    },
    {
      title: "指标类型",
      dataIndex: "type",
      // customRender: ({ text }: { text: IndicatorTypeEnum }) =>
      //   indicatorTypeMap[text],
      width: 50,
      resizable: true,
      ellipsis: true,
    },
    weightsColumn,
    scoreColumn,
    {
      title: "审核状态",
      dataIndex: "approvalStatusName",
      width: 100,
      resizable: true,
      ellipsis: true,
      // customRender({ text, record }: any) {
      //   return record.nodeType === 1 ? approvalStatusMap[text || 0]?.text : "";
      // },
    },
    {
      title: "操作",
      dataIndex: "action",
      width: 100,
      resizable: true,
      ellipsis: true,
    },
  ]);
export const getBackendIndicatorColumns = (status: number) =>
  cloneDeep([
    {
      title: "名称",
      dataIndex: "name",
      width: 100,
      resizable: true,
      ellipsis: true,
    },
    {
      title: "指标类型",
      dataIndex: "type",
      // customRender: ({ text }: { text: IndicatorTypeEnum }) =>
      //   indicatorTypeMap[text],
      width: 50,
      resizable: true,
      ellipsis: true,
    },
    weightsColumn,
    scoreColumn,
    {
      title: "状态",
      dataIndex: "statusName",
      width: 100,
      resizable: true,
      ellipsis: true,
      // customRender({ text, record }: any) {
      //   return record.nodeType === 1 ? text : "";
      // },
    },
    ...(status >= 400
      ? [
          {
            title: "操作",
            dataIndex: "action",
            width: 100,
          },
        ]
      : []),
  ]);
